from twisted.web.resource import Resource

from blocking_resource import AbcResource
from blocking_resource import BlockingResource
from blocking_resource import NoneResource
from blocking_resource import NormalHtmlResource
from blocking_resource import FileResource
from command_line import CommandLineResource
from login import LoginResource
from online_user import OnlineUserList
from sgs.sgs_player import SGSPlayerList

class Root(Resource):
    def getChild(self, name, request):
        if not name:
            name = 'sgs/pages/signin.html'
            return NormalHtmlResource(name)

        processors = {'': BlockingResource('index.html'),
                      'abc': AbcResource(),
                      'cmd': CommandLineResource(),
                      'user': OnlineUserList(),
                      'seat': SGSPlayerList(),
                      'signin': LoginResource(),
                      'favicon.ico': NoneResource()}

        if processors.has_key(name):
            return processors[name]
        else:
            name = request.path
            print "Request: %s" % name
            if name.endswith('html') or name.endswith('htm'):
                return NormalHtmlResource(name)
            else:
                return FileResource(name)

    def render(self, request):
        raise "NOT FOUND"
